package com.shimao.celnet.payment.controller;

import com.shimao.celnet.payment.form.PPayForm;
import com.shimao.celnet.payment.service.BEstateService;
import com.shimao.celnet.payment.service.PPayService;
import com.shimao.celnet.payment.service.SCodeNameService;
import com.shimao.celnet.payment.service.report.PPayDayReportService;
import com.shimao.celnet.payment.util.FinalUtil;
import com.shimao.celnet.payment.util.MyDateUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 支付记录
 * Created by ensure on 2017/12/04.
 *
 */
@Controller
@RequestMapping("/pays")
public class PPayController {
    protected  Logger logger = Logger.getLogger(this.getClass());

    @Autowired
    private SCodeNameService sCodeNameService;

    @Autowired
    private BEstateService bEstateService;

    @Autowired
    private PPayService localService;

    @Autowired
    private PPayDayReportService pPayDayReportService;


    /**
     * 分页列表查询
     * @param formBean
     * @param pageActionNm
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String getAll(@ModelAttribute PPayForm formBean, String pageActionNm, Model model){
        logger.info("查询列表页面--开始");

        if(StringUtils.isNotEmpty(formBean.getGuid())){
            //更新，新增后，重新刷新情况，查询条件清空
            formBean=new PPayForm();
        }

        //当前页码设定
        int pageNum=FinalUtil.PAGE_Fist_NUM;

        if(formBean.isIsLastPage()){
            pageNum=formBean.getPages();
        }

        if(!StringUtils.isEmpty(pageActionNm) && !"0".equals(pageActionNm)){
            pageNum=Integer.valueOf(pageActionNm);
        }

        //查询开始日期
        if(StringUtils.isEmpty(formBean.getPayStartTime())) {
            formBean.setPayStartTime(MyDateUtil.StrToDateYmd(formBean.getPayStartTime()));
        }
        //查询结束日期
        if(StringUtils.isEmpty(formBean.getPayEndTime())) {
            formBean.setPayEndTime(MyDateUtil.StrToDateYmd(formBean.getPayEndTime()));
        }

        //页面数据查询结果
        formBean = localService.getByPage(formBean, pageNum, FinalUtil.PAGE_LENGHT);

        //小区：列表取得
        formBean.setEstateList(bEstateService.getAll());

        //业务类型取得
        formBean.setBusinessTypeList(sCodeNameService.getCodeNameListByType(FinalUtil.CODE_NAME_BUSINESS_TYPE));

        //支付方式取得
        formBean.setPayTypeList(sCodeNameService.getCodeNameListByType(FinalUtil.CODE_NAME_PAY_TYPE));

        //支付状态取得
        formBean.setPayStatusList(sCodeNameService.getCodeNameListByType(FinalUtil.CODE_NAME_PAY_STATUS));

        model.addAttribute("formBean", formBean);

        logger.info("查询列表页面--结束");

        return "pay/payList";
    }

    /**
     * 详情初始化
     * @param
     * @return
     */
    @RequestMapping("/info")
    public  String  getInfo(@RequestParam String guid, Model model) {
        logger.info("详情页面--开始");

        model.addAttribute("formBean",localService.getInfo(guid));
        logger.info("详情页面--结束");
        return "pay/payInfo";
    }

}
